Skip to content

Conversation

@cs3b
Copy link

@cs3b cs3b commented Apr 1, 2025

Updated: Prompts Feature with Main Branch Alignment

This PR has been rebased onto main and updated to align with current architecture.

Major Changes from Rebase:

1. ServerFiltering Integration

  • Prompts now support the filtering architecture
  • Dynamic prompt filtering based on request context
  • Consistent with tool and resource filtering

2. Feature Parity with Tools

  • Added tags support to prompts
  • Added metadata support
  • Added annotations support
  • Added authorization blocks
  • Headers parameter for all prompts

3. Rails Integration

  • Generator creates app/prompts/ directory
  • ApplicationPrompt base class
  • Auto-discovery of prompt descendants
  • ActionPrompt alias for Rails conventions

Testing:

  • All tests updated for new architecture
  • New tests for prompt features
  • Integration tests passing
  • MCP inspector validated

Addresses Reviewer Feedback:

  • ✅ ApplicationPrompt.descendants registration implemented
  • ✅ Rails generator updated with demo prompt generation
  • ✅ Consistent with tools/resources patterns
  • ✅ All architectural changes from main branch integrated

@cs3b
Copy link
Author

cs3b commented Apr 1, 2025

@yjacquin it's still a WIP, please look at the examples - do you like dsl like this (we have to handle multiple message on the output), and i see value to have support for erb templates for prompts (might be especial useful if you want to keep the in certain format markdown md.erb / xml - xml.erb )

Just let me know how do you see it

@cs3b cs3b marked this pull request as draft April 1, 2025 01:38
@yjacquin
Copy link
Owner

yjacquin commented Apr 2, 2025

@yjacquin it's still a WIP, please look at the examples - do you like dsl like this (we have to handle multiple message on the output), and i see value to have support for erb templates for prompts (might be especial useful if you want to keep the in certain format markdown md.erb / xml - xml.erb )

Just let me know how do you see it

@cs3b I love it ! The erb template is a clever addition.
Thanks a lot for your qualitative work :)
Let me know if I can help you with this PR !
Sorry I haven't been able to review earlier 🙏

@cs3b cs3b force-pushed the server-prompts-feature branch 3 times, most recently from b75c14c to 191a3a0 Compare April 3, 2025 21:29
@cs3b cs3b marked this pull request as ready for review April 3, 2025 23:36
@cs3b cs3b changed the title (WIP) Server prompts feature Feature :: Server :: Prompts Apr 3, 2025
@cs3b cs3b changed the title Feature :: Server :: Prompts feat: server prompts Apr 3, 2025
@cs3b
Copy link
Author

cs3b commented Apr 3, 2025

Feature ready to review and merge @yjacquin

Copy link
Owner

@yjacquin yjacquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @cs3b for the great work !
I think it's a great feature to add and we're near it being ready to get merged and added to the incoming 1.1.0.

We could also add this to the rails integration in the same fashion it has been done for tools and resources, wdyt ? It can also be done in a later iteration.

cs3b added a commit to cs3b/fast-mcp that referenced this pull request Apr 13, 2025
- Removed multi_message_prompt.rb as it's no longer needed after simplifying the messages API
- The example was demonstrating the array-based API which has been removed in Task 3
- The inline_prompt.rb example now serves as the primary example for prompt functionality

This change aligns the examples with the implementation changes made in PR yjacquin#21.
cs3b added a commit to cs3b/fast-mcp that referenced this pull request Apr 14, 2025
Key changes:
- Added robust prompt registration and handling in Server class
- Implemented base64 validation for image content to ensure MCP compliance
- Simplified messages API to use only keyword arguments for better usability
- Refactored code to follow DRY principles and improve maintainability
- Updated tool_name method to follow the same pattern as prompt_name
- Fixed unused parameters and linter warnings throughout the codebase
- Added comprehensive test coverage for all new functionality
- Added example prompts to demo files for easy adoption
- Reverted version to 1.0.0 as requested by maintainer

This implementation enables developers to create and register prompts that can
generate messages with text, image, and resource content, following the MCP
specification. The code is thoroughly tested and includes examples to
demonstrate proper usage.

All tasks from PR yjacquin#21 feedback have been addressed
@cs3b cs3b force-pushed the server-prompts-feature branch from 9941bcf to 4ebfbf6 Compare April 14, 2025 00:14
cs3b added a commit to cs3b/fast-mcp that referenced this pull request Apr 14, 2025
Key changes:
- Added robust prompt registration and handling in Server class
- Implemented base64 validation for image content to ensure MCP compliance
- Simplified messages API to use only keyword arguments for better usability
- Refactored code to follow DRY principles and improve maintainability
- Updated tool_name method to follow the same pattern as prompt_name
- Fixed unused parameters and linter warnings throughout the codebase
- Added comprehensive test coverage for all new functionality
- Added example prompts to demo files for easy adoption
- Reverted version to 1.0.0 as requested by maintainer

This implementation enables developers to create and register prompts that can
generate messages with text, image, and resource content, following the MCP
specification. The code is thoroughly tested and includes examples to
demonstrate proper usage.

All tasks from PR yjacquin#21 feedback have been addressed
@cs3b cs3b force-pushed the server-prompts-feature branch from 4ebfbf6 to 46d5948 Compare April 14, 2025 00:19
cs3b added a commit to cs3b/fast-mcp that referenced this pull request Apr 14, 2025
Key changes:
- Added robust prompt registration and handling in Server class
- Implemented base64 validation for image content to ensure MCP compliance
- Simplified messages API to use only keyword arguments for better usability
- Refactored code to follow DRY principles and improve maintainability
- Updated tool_name method to follow the same pattern as prompt_name
- Fixed unused parameters and linter warnings throughout the codebase
- Added comprehensive test coverage for all new functionality
- Added example prompts to demo files for easy adoption
- Reverted version to 1.0.0 as requested by maintainer

This implementation enables developers to create and register prompts that can
generate messages with text, image, and resource content, following the MCP
specification. The code is thoroughly tested and includes examples to
demonstrate proper usage.

All tasks from PR yjacquin#21 feedback have been addressed
@cs3b cs3b force-pushed the server-prompts-feature branch from 46d5948 to f1835b3 Compare April 14, 2025 00:21
@cs3b
Copy link
Author

cs3b commented Apr 14, 2025

I've applied feedback and rebased against main. Keep the commits unsquashed so it will easier to review

hope this time we will be able to merge :-)

Waiting for your feedback @yjacquin

@mariochavez
Copy link

Hi! I wasn't aware of this Pull Request, so yesterday I added support for prompts too. https://github.com/mariochavez/fast-mcp/tree/add-prompt-support

If this PR is ready, other than the current merge conflicts, can we expect it to land anytime soon?


def call(code:, programming_language: nil)
assistant_template = File.read(File.join(File.dirname(__FILE__), 'templates/code_review_assistant.erb'))
user_template = File.read(File.join(File.dirname(__FILE__), 'templates/code_review_user.erb'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these files are not that big, perhaps it would be easy to read and use as inline ERB templates right in this file.

I'm not part of the team, so this is for @yjacquin to decide

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, in case of prompt is short inline is recommended - this is just an example, that it is possible

README.md Outdated

# Define a prompt by inheriting from FastMcp::Prompt
class GreetingPrompt < FastMcp::Prompt
prompt_name 'greeting'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps this can be just "name"? prompt_name within FastMcp::Prompt sounds a bit repetitive.

Python https://gofastmcp.com/servers/prompts
and
node https://github.com/punkpeye/fastmcp/blob/main/src/examples/addition.ts#L170 version call it just "name".

/cc @yjacquin

Copy link
Author

@cs3b cs3b Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Ruby, using :name as an attribute can be problematic in certain contexts due to naming conflicts.

Module.name      # => "Module"
MyClass.name     # => "MyClass"
some_object.name # can be defined implicitly

Additionaly this the convention for this project see

def tool_name(name = nil)

there was no feedback from the @yjacquin since beginning of April ( until he will say what next, i'm not working actively on this). Still prompts are a very powerful feature (especial when mcp is attached to ai agent)

@Linell
Copy link

Linell commented Jun 13, 2025

Thank you for your work on this! I would love to see it merged into main soon.

docs/prompts.md Outdated

arguments do
required(:document_type).filled(:string).description("Type of XML document")
required(:elements).array.description("Elements to include")
Copy link

@nfedyashev nfedyashev Jun 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cs3b I think there must be a typo here

/home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/value.rb:62:in `call': wrong number of arguments (given 0, expected at least 1) (ArgumentError)
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:63:in `block (2 levels) in value'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:208:in `append_macro'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:62:in `block in value'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:251:in `extract_type_spec'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:61:in `value'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/array.rb:22:in `block in value'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:251:in `extract_type_spec'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/array.rb:16:in `value'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:178:in `block in array'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:208:in `append_macro'
	from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:177:in `array'
	from /home/nfedyashev/Projects/appfoo/app/resources/xml_prompt.rb:7:in `block in <class:XmlPrompt>'

.array(:hash). doesn't seem to work either:

Invalid arguments for prompt xml_generator: {"elements":["must be an array"],"attributes":["must be a hash"]}
Sending response: {:jsonrpc=>"2.0", :error=>{:code=>-32602, :message=>"{\"elements\":[\"must be an array\"],\"attributes\":[\"must be a hash\"]}"}, :id=>8}

@nfedyashev
Copy link

@cs3b A few comments

  1. perhaps this PR can be slightly updated to be more consistent with how tools and resources are configured.
    From what I see it is lacking a way to register all prompts(*ApplicationPrompt.descendants)

https://github.com/yjacquin/fast-mcp?tab=readme-ov-file#-fast-ruby-on-rails-implementation

  1. install_generator is a bit outdated and seems like lacking demo prompt generation
    https://github.com/yjacquin/fast-mcp/blob/main/lib/generators/fast_mcp/install/install_generator.rb#L28 in this case README needs to be updated as well

@nfedyashev
Copy link

Other than a few comments above it works great! Thank you very much @cs3b
image

@grantmca
Copy link

Hey! This MR looks great, wanted to check in on the status, looks like it has been on hold for a couple of months. @yjacquin What does the timeline look like for supporting prompts? Thanks for all the great work @cs3b!

@pyrabbit
Copy link

Would love to see this merged -- let me know if I can help.

@cs3b cs3b force-pushed the server-prompts-feature branch from 5e25cca to 26b9871 Compare August 17, 2025 21:53
@cs3b cs3b force-pushed the server-prompts-feature branch 5 times, most recently from dc7b377 to ea034eb Compare August 17, 2025 22:19
@cs3b
Copy link
Author

cs3b commented Aug 17, 2025

Feature ready to review and merge @yjacquin

/cc @pyrabbit @grantmca @nfedyashev @Linell @mariochavez

@cs3b cs3b requested review from nfedyashev and yjacquin August 18, 2025 10:12
@cs3b cs3b force-pushed the server-prompts-feature branch from 31931f4 to ee7326f Compare August 18, 2025 10:20
Implements full Model Context Protocol (MCP) prompts support per specification.

Core Features:
- New Prompt class with message creation and validation
- Dry::Schema-based argument validation (same as tools)
- ERB template support for structured prompt messages
- Multiple message formats (hash, array, MessageBuilder pattern)
- Support for text, image, and resource content types

API Design:
- MessageBuilder for fluent message construction
- Flexible messages() method supporting multiple same-role messages
- Base64 validation for image content compliance
- Auto-naming from class names (CodeReviewPrompt → code_review)

Feature Parity with Tools:
- Authorization blocks for access control
- Tags, metadata, and annotations support
- Integration with ServerFiltering for dynamic filtering
- Headers support for authorization context

Server Integration:
- Added prompts/list and prompts/get endpoints
- Prompt registration methods (register_prompt, register_prompts)
- Notification support for prompts list changes

Rails Support:
- Generator for creating new prompts (rails g fast_mcp:install)
- ApplicationPrompt base class
- Auto-loading from app/prompts directory
- Sample prompt template with best practices

Testing & Documentation:
- 900+ lines of comprehensive tests
- Example prompts (few-shot, inline, code review with templates)
- Full documentation in docs/prompts.md
- Rails integration guide updates

Breaking Changes: None - purely additive feature
@cs3b cs3b force-pushed the server-prompts-feature branch from ee7326f to f519045 Compare August 18, 2025 10:23
@nfedyashev
Copy link

@cs3b I haven't reviewed the latest code updates, but as a user I can confirm that it works fine. I'm currently using it as fork of fast-mcp before it gets merged.
Thanks a lot for your effort. Much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants